package com.fjzn.detect.repository.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

/**
 * 用户删除标志枚举
 *
 * @author yzh
 * @since 2021年04月26日10:07:38
 */
public enum UserFlag {
    //
    存在(0,"存在"),删除(1,"删除");

    @EnumValue
    private final int value;
    private final String label;

    UserFlag(int value, String label) {
        this.value = value;
        this.label = label;
    }

    @JsonCreator
    public static UserFlag deserializer(String value) {
        return StringUtils.isNotEmpty(value) ? Arrays.stream(UserFlag.values()).filter(e -> e.label.equals(value) ||
                String.valueOf(e.value).equals(value) || e.toString().equals(value)).findFirst().orElseThrow(()-> new RuntimeException("枚举入参错误！")) : null;
    }

    public int getValue() {
        return value;
    }

    @JsonIgnore
    public String getLabel() {
        return label;
    }
}
